Learning Git
Where I Learn Version Control
Learning
It has been a good while since I last posted. Time has gotten away from me. Thankfully, I can also fall back on the “I’ve been busy” shtick. I’ll lean on that. A quick glance on my GitHub profile shows that I have been “fairly” busy. So my “excuse” isn’t far off.
Housekeeping
Since my last post, I have hit a lot of personal milestones. I’ve become a little more comfortable with coding. As someone who is self-taught, it feels like a huge accomplishment to be able to say that. However, there is always more to learn, to improve, and skills to develop. One of the most important ones is Version Control.
For those in academia, GitHub is the repository host of choice. Though, I think Codeberg is a good one too and I have begun mirroring many of my projects. Hopefully I can wean myself from Github in the future, since the projects on GitHub is used to train Microsoft’s Copilot, and potentially exposing private GitHub repositories. Codeberg, as far as I know, cannot be used to train LLMs.
All of that is for another post or venue. For now, I wanted to share how I use Git and some basic commands I use.
How I Started Using Git
As my projects have become bigger and ambitious, it has become vital to record and track the changes to my code. This is a natural progression for any developer.
I started writing my projects in Jupyter Notebooks. I love the ability to write in distinct code blocks and to immediately get results printed on script. It helps that each code block can be run out of order, which allows testing and learning of code or custom API. Importantly, with the mix of code and markdown blocks, Jupyter Notebooks are great ways to communicate, share, and teach others your code.
My original interaction with Jupyter Notebooks was through the traditional portal - the localhost connection. It was simple and easy.
As I got comfortable with simple command scripts, I began making more complicated functions, which requires better organization skills. On the advice of a friend, I began using Integrated Development Environment (IDE)s. There are plenty out there, like VSCode and Spyder. But I gravitated toward the JetBrains software suite - particularly PyCharm and IntelliJ IDEA.
I like the JetBrains software because of the look of the interface and the ability to customize how it looks. I am an insane person and will change my IDE theme each day depending on my mood. Everyone is different, so play around with each one and find one that you like.
A main advantage with PyCharm is its integration with Git. It is there from the get go and ready for set up. Plugin with your GitHub account and users are ready to commit, push, or pull their projects. The GUI made it easy peasy! My workflow became:
- Create repository on GitHub
- Clone repository through PyCharm onto my machine
- Code
- Commit/Push/Pull as needed
It was simple and I got comfortable with that for a long time.
However, PyCharm is mainly “connected” to GitHub. As I begin to transition/mirror projects to Codeberg, I found that the GUI becomes unfriendly and clunky. That has caused me to learn a few command line codes that I found useful.
Git Commands I Use
These command line tools are easy ways to connect a project to Git protocols. Importantly, they do not need a specific IDE to be used. All you need is a terminal/command line interface. It is a step up in my coding abilities!
My main machine is a MacOS. Thus, these commands are used in the Terminal. Depending on your machine, you should be able to copy/paste these commands to get things working too.
Check if git is installed:
git --version
Initialize Git in project folder:
git init
Confirm git tracking:
git status
If a git repository is made on your GitHub/Codeberg account:
git remote add origin https://github.com/your-username/repo.git
If you want to add multiple repositories/remotes to your project or want to check which ones are connected to your project:
git remote -v
If you want to rename your remotes:
git remote rename original_name new_name
Stage all changes in project:
git add .
or if you want to stage specific files:
git add name_of_file
Commit changes:
git commit -m "message"
Push to repository (first time):
git push u- origin main
Push to repository (subsequent times)
git push
Pull changes:
git pull
Those are the main commands that I have learned to use. There are a ton of others that may come in handy to users. I found a nice cheatsheet here. For my main uses though, I still have the GUI to use. If things break, I hope I can figure things out in the future!